home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Easy Applet Builder v1.7 / _SETUP.1 / ScrollUpDown.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  11.2 KB  |  612 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.io.BufferedReader;
  13. import java.io.IOException;
  14. import java.io.InputStreamReader;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.net.URLEncoder;
  18. import java.util.Vector;
  19.  
  20. public class ScrollUpDown extends Applet implements Runnable, MouseListener {
  21.    private Thread thread;
  22.    // $FF: renamed from: b java.awt.Graphics
  23.    private Graphics field_0;
  24.    private Image buffer;
  25.    private boolean loaded;
  26.    private boolean paintable = false;
  27.    private boolean move = true;
  28.    private boolean firstime = true;
  29.    // $FF: renamed from: on boolean
  30.    private boolean field_1 = true;
  31.    // $FF: renamed from: wi int
  32.    private int field_2;
  33.    // $FF: renamed from: he int
  34.    private int field_3;
  35.    private int decx;
  36.    private int pause;
  37.    private int heightSpace;
  38.    private int textHeight;
  39.    private Color textColor;
  40.    private Color backColor;
  41.    private int wiBack;
  42.    private int heBack;
  43.    private Color enterBackColor;
  44.    private AudioClip sound;
  45.    private AudioClip clicSound;
  46.    private AudioClip enterSound;
  47.    private boolean loopSound;
  48.    private String link;
  49.    private String statusBarText;
  50.    private String text;
  51.    private Image textImage;
  52.    private int textImageHeight;
  53.    // $FF: renamed from: Y int
  54.    private int field_4;
  55.    private int YStep;
  56.    private int direction;
  57.    private boolean freeze = false;
  58.    private int pause2;
  59.  
  60.    public String getAppletInfo() {
  61.       return "Name: ScrollUpDown\r\nAuthor: Taiji Software\r\n";
  62.    }
  63.  
  64.    public ScrollUpDown() {
  65.       this.move = true;
  66.       this.pause = 100;
  67.       this.heightSpace = 15;
  68.       this.decx = 10;
  69.       this.textHeight = 20;
  70.       this.YStep = 2;
  71.       this.direction = 1;
  72.       this.pause2 = 3000;
  73.       ((Component)this).addMouseListener(this);
  74.    }
  75.  
  76.    public void register() {
  77.       try {
  78.          URL u = new URL("http://www.taijisoftware.com");
  79.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  80.       } catch (Exception e) {
  81.          System.out.println(e);
  82.          this.stop();
  83.       }
  84.    }
  85.  
  86.    public void init() {
  87.       String codeBase = null;
  88.  
  89.       try {
  90.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  91.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  92.          codeBase = codeBase.toUpperCase();
  93.       } catch (Exception var9) {
  94.       }
  95.  
  96.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  97.          String regCode = ((Applet)this).getParameter("registration_code");
  98.          if (regCode == null) {
  99.             regCode = ((Applet)this).getParameter("reg_domain");
  100.             if (regCode == null) {
  101.                this.register();
  102.             } else {
  103.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  104.                   codeBase = "WWW." + codeBase;
  105.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  106.                   codeBase = codeBase.substring(4);
  107.                }
  108.  
  109.                char[] chars = new char[codeBase.length()];
  110.                codeBase.getChars(0, codeBase.length(), chars, 0);
  111.                String key = new String("haricot");
  112.                char[] chars2 = new char[key.length()];
  113.                key.getChars(0, key.length(), chars2, 0);
  114.  
  115.                for(int i = 0; i < codeBase.length(); ++i) {
  116.                   int j;
  117.                   if (i >= key.length()) {
  118.                      j = i - key.length() * (i / key.length());
  119.                   } else {
  120.                      j = i;
  121.                   }
  122.  
  123.                   chars[i] += chars2[j];
  124.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  125.                }
  126.  
  127.                String res = new String(chars);
  128.                if (!res.equalsIgnoreCase(regCode)) {
  129.                   this.register();
  130.                }
  131.             }
  132.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  133.             this.register();
  134.          }
  135.       }
  136.  
  137.       this.getParameters();
  138.       if (this.sound != null) {
  139.          if (this.loopSound) {
  140.             this.sound.loop();
  141.             return;
  142.          }
  143.  
  144.          this.sound.play();
  145.       }
  146.  
  147.    }
  148.  
  149.    public void getParameters() {
  150.       String s = ((Applet)this).getParameter("pause");
  151.       if (s != null) {
  152.          this.pause = Integer.parseInt(s);
  153.       }
  154.  
  155.       this.field_2 = ((Component)this).getSize().width;
  156.       this.field_3 = ((Component)this).getSize().height;
  157.       this.text = ((Applet)this).getParameter("text");
  158.       this.textColor = this.getColor("text_color");
  159.       this.backColor = this.getColor("background_color");
  160.       ((Component)this).setBackground(this.backColor);
  161.       s = ((Applet)this).getParameter("height_space");
  162.       if (s != null) {
  163.          this.heightSpace = Integer.parseInt(s);
  164.       }
  165.  
  166.       s = ((Applet)this).getParameter("text_height");
  167.       if (s != null) {
  168.          this.textHeight = Integer.parseInt(s);
  169.       }
  170.  
  171.       s = ((Applet)this).getParameter("width_shift");
  172.       if (s != null) {
  173.          this.decx = Integer.parseInt(s);
  174.       }
  175.  
  176.       s = ((Applet)this).getParameter("text_step");
  177.       if (s != null) {
  178.          this.YStep = Integer.parseInt(s);
  179.       }
  180.  
  181.       s = ((Applet)this).getParameter("direction");
  182.       if (s != null && s.equals("down")) {
  183.          this.direction = -1;
  184.       }
  185.  
  186.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  187.       s = ((Applet)this).getParameter("sound_name");
  188.       if (s != null) {
  189.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  190.       }
  191.  
  192.       s = ((Applet)this).getParameter("loop_sound");
  193.       if (s != null) {
  194.          if (s.equals("yes")) {
  195.             this.loopSound = true;
  196.          } else {
  197.             this.loopSound = false;
  198.          }
  199.       }
  200.  
  201.       s = ((Applet)this).getParameter("clic_sound_name");
  202.       if (s != null) {
  203.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  204.       }
  205.  
  206.       s = ((Applet)this).getParameter("enter_sound_name");
  207.       if (s != null) {
  208.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  209.       }
  210.  
  211.       this.link = ((Applet)this).getParameter("link");
  212.       s = ((Applet)this).getParameter("on_click_pause");
  213.       if (s != null) {
  214.          if (s.equals("yes")) {
  215.             this.freeze = true;
  216.          } else {
  217.             this.freeze = false;
  218.          }
  219.       }
  220.  
  221.       s = ((Applet)this).getParameter("pause2");
  222.       if (s != null) {
  223.          this.pause2 = Integer.parseInt(s);
  224.       }
  225.  
  226.    }
  227.  
  228.    public Color getColor(String param) {
  229.       String s = ((Applet)this).getParameter(param);
  230.       if (s != null) {
  231.          if (s.substring(0, 1).equals("#")) {
  232.             s = s.substring(1);
  233.             int i = Integer.parseInt(s, 16);
  234.             return new Color(i);
  235.          } else {
  236.             return null;
  237.          }
  238.       } else {
  239.          return null;
  240.       }
  241.    }
  242.  
  243.    public final void paint(Graphics g) {
  244.       if (this.paintable) {
  245.          this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  246.          this.field_0.drawImage(this.textImage, 0, this.field_4, this);
  247.          g.drawImage(this.buffer, 0, 0, this);
  248.       }
  249.  
  250.    }
  251.  
  252.    public final void update(Graphics g) {
  253.       this.paint(g);
  254.    }
  255.  
  256.    public void start() {
  257.       this.move = true;
  258.       if (this.thread == null) {
  259.          this.thread = new Thread(this);
  260.          this.thread.start();
  261.       }
  262.  
  263.    }
  264.  
  265.    public void stop() {
  266.       if (this.thread != null) {
  267.          this.move = false;
  268.          this.thread = null;
  269.       }
  270.  
  271.       if (this.sound != null) {
  272.          this.sound.stop();
  273.       }
  274.  
  275.    }
  276.  
  277.    public void run() {
  278.       if (this.firstime) {
  279.          this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  280.          this.field_0 = this.buffer.getGraphics();
  281.          String fontName = ((Applet)this).getParameter("text_font");
  282.          if (fontName == null) {
  283.             fontName = "TimesRoman";
  284.          }
  285.  
  286.          int style = 1;
  287.          String s = ((Applet)this).getParameter("text_style");
  288.          if (s != null) {
  289.             if (s.equals("bold")) {
  290.                style = 1;
  291.             } else if (s.equals("italic")) {
  292.                style = 2;
  293.             } else if (s.equals("bold_italic")) {
  294.                style = 3;
  295.             } else {
  296.                style = 0;
  297.             }
  298.          }
  299.  
  300.          int m = 0;
  301.          int c = 0;
  302.          if (this.text != null) {
  303.             while((c = this.text.indexOf("#", c)) != -1) {
  304.                ++c;
  305.                ++m;
  306.             }
  307.          } else {
  308.             BufferedReader br = null;
  309.             String filename = ((Applet)this).getParameter("filename");
  310.             if (filename == null) {
  311.                System.out.println("Error: Text file not found !");
  312.                return;
  313.             }
  314.  
  315.             try {
  316.                br = new BufferedReader(new InputStreamReader((new URL(((Applet)this).getCodeBase(), filename)).openStream()));
  317.             } catch (Exception e2) {
  318.                System.out.println(e2);
  319.             }
  320.  
  321.             s = "";
  322.             this.field_0.setFont(new Font(fontName, style, this.textHeight));
  323.             FontMetrics fm = this.field_0.getFontMetrics();
  324.  
  325.             try {
  326.                while((s = br.readLine()) != null) {
  327.                   m += this.warp(s, fm).length;
  328.                }
  329.             } catch (IOException ex3) {
  330.                System.out.println(ex3);
  331.             }
  332.          }
  333.  
  334.          this.textImageHeight = (m + 1) * (this.textHeight + this.heightSpace) + this.heightSpace;
  335.          this.textImage = ((Component)this).createImage(this.field_2, this.textImageHeight);
  336.          Graphics e = this.textImage.getGraphics();
  337.          e.setFont(new Font(fontName, style, this.textHeight));
  338.          e.setColor(this.textColor);
  339.          int hPos = this.textHeight;
  340.          if (this.text != null) {
  341.             if (m != 0) {
  342.                int[] index = new int[m];
  343.                m = 0;
  344.  
  345.                FontMetrics fm;
  346.                for(fm = e.getFontMetrics(); (c = this.text.indexOf("#", c)) != -1; ++m) {
  347.                   index[m] = c;
  348.                   String line;
  349.                   if (m == 0) {
  350.                      line = this.text.substring(0, index[0]);
  351.                   } else {
  352.                      line = this.text.substring(index[m - 1] + 1, index[m]);
  353.                   }
  354.  
  355.                   int x = this.decx;
  356.                   if (this.decx == -1) {
  357.                      x = (this.field_2 - fm.stringWidth(line)) / 2;
  358.                   }
  359.  
  360.                   e.drawString(line, x, hPos);
  361.                   hPos += this.textHeight + this.heightSpace;
  362.                   ++c;
  363.                }
  364.  
  365.                String line = this.text.substring(index[m - 1] + 1);
  366.                int x = this.decx;
  367.                if (this.decx == -1) {
  368.                   x = (this.field_2 - fm.stringWidth(line)) / 2;
  369.                }
  370.  
  371.                e.drawString(line, x, hPos);
  372.             } else {
  373.                e.drawString(this.text, this.decx, hPos);
  374.             }
  375.          } else {
  376.             BufferedReader br = null;
  377.             String filename = ((Applet)this).getParameter("filename");
  378.             if (filename == null) {
  379.                System.out.println("Error: Text file not found !");
  380.                return;
  381.             }
  382.  
  383.             try {
  384.                br = new BufferedReader(new InputStreamReader((new URL(((Applet)this).getCodeBase(), filename)).openStream()));
  385.             } catch (Exception e2) {
  386.                System.out.println(e2);
  387.             }
  388.  
  389.             s = "";
  390.  
  391.             try {
  392.                FontMetrics fm = e.getFontMetrics();
  393.  
  394.                while((s = br.readLine()) != null) {
  395.                   String[] str = this.warp(s, fm);
  396.  
  397.                   for(int i = 0; i < str.length; ++i) {
  398.                      int x = this.decx;
  399.                      if (this.decx == -1) {
  400.                         x = (this.field_2 - fm.stringWidth(str[i])) / 2;
  401.                      }
  402.  
  403.                      e.drawString(str[i], x, hPos);
  404.                      hPos += this.textHeight + this.heightSpace;
  405.                   }
  406.                }
  407.             } catch (IOException ex3) {
  408.                System.out.println(ex3);
  409.             }
  410.          }
  411.  
  412.          e.dispose();
  413.          this.firstime = false;
  414.          this.paintable = true;
  415.       }
  416.  
  417.       if (this.direction == -1) {
  418.          this.field_4 = -this.textImageHeight;
  419.       } else {
  420.          this.field_4 = this.field_3;
  421.       }
  422.  
  423.       while(this.move) {
  424.          while(this.field_1) {
  425.             do {
  426.                ((Component)this).repaint();
  427.                if (this.direction == -1) {
  428.                   this.field_4 += this.YStep;
  429.                   if (this.field_4 > this.field_3) {
  430.                      this.field_4 = -this.textImageHeight;
  431.                      if (this.pause2 == -1) {
  432.                         return;
  433.                      }
  434.  
  435.                      try {
  436.                         Thread.sleep((long)this.pause2);
  437.                      } catch (InterruptedException var20) {
  438.                         this.stop();
  439.                      }
  440.                   }
  441.                } else {
  442.                   this.field_4 -= this.YStep;
  443.                   if (this.field_4 < -this.textImageHeight) {
  444.                      this.field_4 = this.field_3;
  445.                      if (this.pause2 == -1) {
  446.                         return;
  447.                      }
  448.  
  449.                      try {
  450.                         Thread.sleep((long)this.pause2);
  451.                      } catch (InterruptedException var19) {
  452.                         this.stop();
  453.                      }
  454.                   }
  455.                }
  456.  
  457.                try {
  458.                   Thread.sleep((long)this.pause);
  459.                } catch (InterruptedException var18) {
  460.                   this.stop();
  461.                }
  462.             } while(this.field_1);
  463.  
  464.             try {
  465.                Thread.sleep(100L);
  466.             } catch (InterruptedException var17) {
  467.                this.stop();
  468.             }
  469.          }
  470.  
  471.          try {
  472.             Thread.sleep(100L);
  473.          } catch (InterruptedException var14) {
  474.             this.stop();
  475.          }
  476.       }
  477.  
  478.    }
  479.  
  480.    public String[] warp(String s, FontMetrics fm) {
  481.       String[] str = null;
  482.       Vector v = new Vector();
  483.       int wi2 = this.field_2 - this.decx - 6;
  484.       int l = 1;
  485.       if (fm.stringWidth(s) >= wi2) {
  486.          int pl = 0;
  487.  
  488.          do {
  489.             int p = s.indexOf(" ", pl + 1);
  490.             if (p == -1) {
  491.                p = s.length();
  492.             }
  493.  
  494.             if (fm.stringWidth(s.substring(0, p)) <= wi2) {
  495.                pl = p;
  496.             } else {
  497.                if (pl == 0) {
  498.                   while(true) {
  499.                      --p;
  500.                      if (fm.stringWidth(s.substring(0, p)) < wi2) {
  501.                         v.addElement(s.substring(0, p));
  502.                         s = s.substring(p);
  503.                         break;
  504.                      }
  505.                   }
  506.                } else {
  507.                   v.addElement(s.substring(0, pl));
  508.                   s = s.substring(pl + 1);
  509.                }
  510.  
  511.                ++l;
  512.                pl = 0;
  513.             }
  514.          } while(fm.stringWidth(s) >= wi2);
  515.  
  516.          ++l;
  517.          v.addElement(s);
  518.       } else {
  519.          v.addElement(s);
  520.       }
  521.  
  522.       str = new String[v.size()];
  523.       v.copyInto(str);
  524.       return str;
  525.    }
  526.  
  527.    public URL giveURL(String url) {
  528.       try {
  529.          if (url.toUpperCase().startsWith("HTTP")) {
  530.             return new URL(url);
  531.          } else if (url.toUpperCase().startsWith("FTP")) {
  532.             int p = url.indexOf(":");
  533.             int p2 = url.indexOf(":", p + 1);
  534.             if (p2 != -1) {
  535.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  536.             }
  537.  
  538.             p = url.indexOf("%40");
  539.             if (p != -1) {
  540.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  541.             }
  542.  
  543.             return new URL(url);
  544.          } else {
  545.             return new URL(((Applet)this).getCodeBase(), url);
  546.          }
  547.       } catch (MalformedURLException e) {
  548.          System.out.println(e);
  549.          return null;
  550.       }
  551.    }
  552.  
  553.    public void mouseClicked(MouseEvent e) {
  554.    }
  555.  
  556.    public void mouseEntered(MouseEvent e) {
  557.       if (this.enterBackColor != null) {
  558.          ((Component)this).setBackground(this.enterBackColor);
  559.          ((Component)this).repaint();
  560.       }
  561.  
  562.       if (this.statusBarText != null) {
  563.          ((Applet)this).showStatus(this.statusBarText);
  564.       }
  565.  
  566.       if (this.enterSound != null) {
  567.          this.enterSound.play();
  568.       }
  569.  
  570.       if (this.link != null) {
  571.          ((Component)this).setCursor(new Cursor(12));
  572.       }
  573.  
  574.    }
  575.  
  576.    public void mouseExited(MouseEvent e) {
  577.       if (this.enterBackColor != null) {
  578.          ((Component)this).setBackground(this.backColor);
  579.          ((Component)this).repaint();
  580.       }
  581.  
  582.       if (this.link != null) {
  583.          ((Component)this).setCursor(new Cursor(0));
  584.       }
  585.  
  586.    }
  587.  
  588.    public void mousePressed(MouseEvent e) {
  589.       if (this.clicSound != null) {
  590.          this.clicSound.play();
  591.       }
  592.  
  593.       if (this.freeze) {
  594.          this.field_1 = !this.field_1;
  595.       }
  596.  
  597.       if (this.link != null) {
  598.          String target = ((Applet)this).getParameter("target");
  599.          if (target == null) {
  600.             target = "_blank";
  601.          }
  602.  
  603.          URL u = this.giveURL(this.link);
  604.          ((Applet)this).getAppletContext().showDocument(u, target);
  605.       }
  606.  
  607.    }
  608.  
  609.    public void mouseReleased(MouseEvent e) {
  610.    }
  611. }
  612.